初学Java 求最大公约数
2024-09-05 13:25:51
import java.util.Scanner;
public class GreatesCommonDivisor {
public static void main(String[] args) {
Scanner input = new Scanner(System.in); System.out.print("Enter first integer: ");
int n1 = input.nextInt();
System.out.print("Enter second integer: ");
int n2 = input.nextInt(); int gcd = ;
int k = ;
while (k <= n1 && k <= n2) {
if (n1 % k == && n2 % k == )
gcd = k;
k++;
} System.out.println("The greatest common divisor for " + n1 + " and " + n2 + " is " + gcd);
}
}
最新文章
- 分布式系统理论进阶 - Paxos
- ajax返回json数据,对其中日期的解析
- 项目安排(离散化+DP)
- CodeSoft随笔 批量连续打印,变量打印,codesoft条码
- 记一次小团队Git实践(中)
- 浏览器查看cookie
- CentOS 7 firewalld使用简介
- Java中类名与文件名的关系
- ios-NSStringFromCGRect直接输出控件的frame
- ajax success 和complete 的区别
- IOS 使用新浪微博SDK
- 恢复sudo的权限的命令
- linux下出现java.net.UnknownHostException
- Laravel创建Model
- js 正则练习之语法高亮
- C++inserter
- Android源码博文集锦1
- mybatis 详解(十一)------ mybatis和spring整合
- git for windows上传项目到github
- 修改windows7中文件的权限
热门文章
- Beats:如何创建一个定制的Elastic Beat
- Leetcode_395. Longest Substring with At Least K Repeating Characters_[Devide and Conquer]
- LintCode之最长单词
- mybatis缓存机制(转)
- Spring 注解配置 WebApplicationContext
- mysqldump - 备份 MySQL 数据库
- HTML5移动应用——小心代码注入风险
- 20190825 On Java8 第十二章 集合
- 函数式编程filter和map的区别
- PHP开发环境搭建及开发工具