我是靠谱客的博主 开心人生,最近开发中收集的这篇文章主要介绍java作业合集168 - 学生Map167 - 学生列表166 - 比较日期158 - 打印双休日165 - 数据类型判断164 - 解析二维数组163 - 各类字符数162 - 字符串153 - 判断回文140 - 家电类151 - 矩阵类139 - 整数数组比较142 - 计算机类149 - 教师类-2150 - 教师类16 - 十进制转二进制,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

175-逆序输出整数

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
for(int i=0;i<N;i++) {
int
num = sc.nextInt();
int sum = 0,tmp = num;
int count = 0;
while(tmp>0) {
count++;
if(count!=1) {
sum*=10;
}
sum+=tmp%10;
tmp/=10;
}
System.out.println(sum);
}
}
}

184-图书列表

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
class Book{
String name;
int price;
String author;
int issue;
Book(String _name,int _price,String _author,int _issue){
name = _name;
price = _price;
author = _author;
issue = _issue;
}
@Override
public boolean equals(Object o) {
Book book = (Book)o;
return name.equals(book.name)&&author.equals(book.author)&&issue==book.issue;
}
}
class BookList{
List<Book> list;
BookList(){
list = new LinkedList();
}
public void addBook(Book b) {
list.add(b);
}
public void searchBook(Book tmp) {
int pos = -1;
for(int i=0;i<list.size();i++) {
Book b = (Book)list.get(i);
if(b.equals(tmp)) {
pos = i;
break;
}
}
if(pos!=-1) {
System.out.println("found: "+pos);
}else {
System.out.println("not found");
}
}
}

168 - 学生Map

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
class Student{
int no;
String name;
int score;
Student(int _no,String _name,int _score){
this.no = _no;
this.name = _name;
this.score = _score;
}
@Override
public String toString() {
return "no:"+no+" name:"+name+" score:"+score;
}
@Override
public boolean equals(Object o) {
Student s = (Student)o;
if(s.no == no)
return true;
else
return false;
}
@Override
public int hashCode() {
int result = 17;
result = 31*result+no;
return result;
}
}
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Map<Integer,Student> map = new HashMap<Integer,Student>();
int N = sc.nextInt();
int no,score;
String name;
for(int i=0;i<N;i++) {
no = sc.nextInt();
name = sc.next();
score = sc.nextInt();
map.put(new Integer(no), new Student(no,name,score));
}
int op_num = sc.nextInt();
for(int i=0;i<op_num;i++) {
String op = sc.next();
switch(op) {
case "add":
no = sc.nextInt();
name = sc.next();
score = sc.nextInt();
map.put(new Integer(no), new Student(no,name,score));
break;
case "delete":
Integer num = new Integer(sc.nextInt());
if(map.containsKey(num))
map.remove(num);
break;
case "set":
Integer num2 = new Integer(sc.nextInt());
score = sc.nextInt();
if(map.containsKey(num2)) {
map.get(num2).score = score;
}
break;
}
}
for(Integer i:map.keySet()) {
Student s = (Student)map.get(i);
System.out.println(s.toString());
}
}
}

167 - 学生列表

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
class Student{
int no;
String name;
int score;
Student(int _no,String _name,int _score){
this.no = _no;
this.name = _name;
this.score = _score;
}
@Override
public String toString() {
return "no:"+no+" name:"+name+" score:"+score;
}
@Override
public boolean equals(Object o) {
Student s = (Student)o;
if(s.no == no)
return true;
else
return false;
}
@Override
public int hashCode() {
int result = 17;
result = 31*result+no;
return result;
}
}
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<Student> list = new LinkedList();
int N = sc.nextInt();
for(int i=0;i<N;i++) {
list.add(new Student(sc.nextInt(),sc.next(),sc.nextInt()));
}
int op_num = sc.nextInt();
int no,score;
for(int i=0;i<op_num;i++) {
String op = sc.next();
switch(op) {
case "add":
list.add(new Student(sc.nextInt(),sc.next(),sc.nextInt()));
break;
case "delete":
no = sc.nextInt();
for(int j=0;j<list.size();j++) {
if(list.get(j).no == no) {
list.remove(j);
break;
}
}
break;
case "set":
no = sc.nextInt();
score = sc.nextInt();
for(int j=0;j<list.size();j++) {
if(list.get(j).no == no) {
list.get(j).score = score;
break;
}
}
break;
}
}
for(int i=0;i<list.size();i++) {
Student s = (Student)list.get(i);
System.out.println(s.toString());
}
}
}

166 - 比较日期

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public class Main{
public static void main(String[] args) throws ParseException {
Scanner sc = new Scanner(System.in);
String s1 = sc.next();
String s2 = sc.next();
SimpleDateFormat sdf = new SimpleDateFormat("MM,dd,yyyy");
Date date_01 = sdf.parse(s1);
Date date_02 = sdf.parse(s2);
int res = date_01.compareTo(date_02);
if(res == -1){
System.out.println("<");
long daysBetween = (date_02.getTime() - date_01.getTime() + 1000000) / 86400000;// 86400000=3600*24*1000
用立即数,减少乘法计算的开销
System.out.println(daysBetween);
}else if(res == 1){
System.out.println(">");
long daysBetween = (date_01.getTime() - date_02.getTime() + 1000000) / 86400000;// 86400000=3600*24*1000
用立即数,减少乘法计算的开销
System.out.println(daysBetween);
}else{
System.out.println("=");
System.out.println("0");
}
}
}

158 - 打印双休日

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Scanner;
public class Main{
public static void main(String[] args) throws ParseException {
Scanner sc = new Scanner(System.in);
int year1[] = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};
int year2[] = new int[]{31,29,31,30,31,30,31,31,30,31,30,31};
int year = sc.nextInt();
int mounth = sc.nextInt();
String s = year+"-";
if (mounth<10)
s+="0";
s = s+mounth+"-";
int day;
if((mounth%4==0&&mounth%100!=0)||(mounth%400==0))
day = year1[mounth-1];
else
day = year2[mounth-1];
for(int i=1;i<=day;i++){
String tmp = s;
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
if(i<10)
tmp+="0";
tmp+=i;
calendar.setTime(sdf.parse(tmp));
int num = calendar.get(Calendar.DAY_OF_WEEK);
if(num==1){
System.out.println(tmp);
}
if(num==7){
System.out.println(tmp);
}
}
}
}

165 - 数据类型判断

import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String ss[] = sc.nextLine().split(" ");
for(int i=0;i<ss.length;i++){
if(ss[i].equals("true")||ss[i].equals("false")){
if(i!=0)
System.out.print(" ");
System.out.print("boolean");
}else{
int num1=0,num2=0,num3=0;
for(int j=0;j<ss[i].length();j++){
char c = ss[i].charAt(j);
if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
num1++;
else if (c=='.')
num2++;
else
num3++;
}
if(i!=0)
System.out.print(" ");
if(num3==0)
System.out.print("String");
else{
if(num2!=0)
System.out.print("double");
else
System.out.print("int");
}
}
}
}
}

164 - 解析二维数组

import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
String ss[] = s.split(";");
for(int i=0;i<ss.length;i++){
String sss[] = ss[i].split(",");
for(int j=0;j<sss.length;j++){
if(j==0)
System.out.print("d["+i+","+j+"] = "+sss[j]);
if(j!=0){
System.out.print(" d["+i+","+j+"] = "+sss[j]);
}
}
System.out.println();
}
}
}

163 - 各类字符数

import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
int upnum = 0,downnum = 0,num = 0;
for(int i=0;i<s.length();i++){
char c = s.charAt(i);
if(c>='A'&&c<='Z')
upnum++;
else if(c>='a'&&c<='z')
downnum++;
else
num++;
}
System.out.print(upnum+"n"+downnum+"
"+num);
}
}

162 - 字符串

import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
char c = sc.next().charAt(0);
sc.nextLine();
String str = sc.next();
int count = 0;
for(int i=0;i<s.length();i++) {
if(s.charAt(i) == c)
count++;
}
System.out.println(count);
String tmp = new StringBuffer(s).reverse().toString();
System.out.println(tmp);
int index = s.indexOf(str,0);
System.out.print(index);
index = index +str.length();
while((index = s.indexOf(str,index))!=-1) {
System.out.print(" "+index);
index = index + str.length();
}
System.out.println();
StringBuffer ss = new StringBuffer(s);
for(int i=0;i<s.length();i++) {
if(i==0) {
if(s.charAt(i+1) == ' ') {
if(s.charAt(i)>='a'&&s.charAt(i)<='z')
ss.setCharAt(i, (char) (s.charAt(i)-'a'+'A'));
}
}else {
if(s.charAt(i-1)==' ') {
if(s.charAt(i)>='a'&&s.charAt(i)<='z')
ss.setCharAt(i, (char) (s.charAt(i)-'a'+'A'));
}
}
}
System.out.println(ss.toString());
}
}

153 - 判断回文


import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int old = sc.nextInt();
int new_num = 0,tmp = old,count = 0;
while(tmp>0) {
count++;
new_num = new_num*10+tmp%10;
tmp/=10;
}
System.out.println(count);
if(new_num == old)
System.out.println("Y");
else
System.out.println("N");
}
}

140 - 家电类

import java.util.Scanner;
interface Appliance{
int getwieght();
}
class TV implements Appliance{
int weight;
TV(int w){
weight = w;
}
@Override
public int getwieght() {
// TODO Auto-generated method stub
return weight;
}
}
class WashMachine implements Appliance{
int weight;
WashMachine(int w){
weight = w;
}
@Override
public int getwieght() {
// TODO Auto-generated method stub
return weight;
}
}
class AirConditioner implements Appliance{
int weight;
AirConditioner(int w){
weight = w;
}
@Override
public int getwieght() {
// TODO Auto-generated method stub
return weight;
}
}
class Trunk{
TV tv[];
int numoftv;
WashMachine wa[];
int numofwa;
AirConditioner air[];
int numofair;
Scanner sc;
int num;
Trunk(int data[][],int a,int b,int c,int n){
numoftv = 0;
numofwa = 0;
numofair = 0;
tv = new TV[a];
wa = new WashMachine[b];
air = new AirConditioner[c];
for(int i=0;i<n;i++) {
if(data[i][0]==1) {
tv[numoftv] = new TV(data[i][1]);
numoftv++;
}else if(data[i][0] == 2) {
wa[numofwa] = new WashMachine(data[i][1]);
numofwa++;
}else {
air[numofair] = new AirConditioner(data[i][1]);
numofair++;
}
}
}
int getsum() {
int sum = 0;
for(int i=0;i<numoftv;i++)
sum+=tv[i].getwieght();
for(int i=0;i<numofwa;i++)
sum+=wa[i].getwieght();
for(int i=0;i<numofair;i++)
sum+=air[i].getwieght();
return sum;
}
}
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int numtv=0,numwa=0,numair=0;
int data[][] = new int[n][2];
for(int i=0;i<n;i++) {
for(int j=0;j<2;j++) {
int a = sc.nextInt();
if(j==0) {
if(a==1)
numtv++;
else if(a==2)
numwa++;
else
numair++;
}
data[i][j] = a;
}
}
Trunk t = new Trunk(data,numtv,numwa,numair,n);
System.out.println(t.getsum());
}
}

151 - 矩阵类

import java.util.Arrays;
import java.util.Scanner;
class Matrix{
double value[][];
int row;
int col;
Matrix(double m[][],int row,int col){
value = new double[row][col];
this.row = row;
this.col = col;
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
value[i][j] = m[i][j];
}
void set(int row, int col, double value){
if(this.row<row||this.col<col)
System.out.println("No such row or col");
else
this.value[row-1][col-1] = value;
}
double get(int row,int col){
if(this.row<row||this.col<col){
System.out.println("No such row or col");
return 0;
} else
return value[row-1][col-1];
}
int width(){
return col;
}
int height(){
return row;
}
Matrix add(Matrix b){
Matrix tmp = new Matrix(value,row,col);
if(b.col==col&&b.row==row){
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
tmp.value[i][j] = value[i][j]+b.value[i][j];
}
return tmp;
}
Matrix multiply(Matrix b){
double tmp[][] = new double[row][b.col];
for(int i=0;i<row;i++){
for(int j=0;j<b.col;j++){
double sum = 0;
for(int k=0;k<col;k++)
sum = sum + value[i][k]*b.value[k][j];
tmp[i][j] = sum;
}
}
return new Matrix(tmp,row,b.col);
}
Matrix transpose(){
double tmp[][] = new double[col][row];
for(int i=0;i<col;i++)
for(int j=0;j<row;j++)
tmp[i][j] = value[j][i];
return
new Matrix(tmp,col,row);
}
@Override
public String toString() {
String s = "";
for(int i=0;i<row;i++) {
for (int j = 0; j < col; j++){
if(j!=0)
s+=" ";
s = s + String.format("%.0f",value[i][j]);
}
s+="n";
}
return s;
}
}
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int row,col;
double value[][];
row = sc.nextInt();
col = sc.nextInt();
value = new double[row][col];
for(int i=0;i<row;i++)
for (int j=0;j<col;j++)
value[i][j] = sc.nextDouble();
Matrix m = new Matrix(value,row,col);
System.out.println("row:"+m.height()+" column:"+m.width());
m.set(sc.nextInt(),sc.nextInt(),sc.nextDouble());
System.out.println("after set value:");
System.out.print(m.toString());
int pos1 = sc.nextInt();
int pos2 = sc.nextInt();
System.out.println("value on ("+pos1+","+pos2+"):"+String.format("%.0f",m.get(pos1,pos2)));
int row2 = sc.nextInt();
int col2 = sc.nextInt();
double value2[][] = new double[row2][col2];
for(int i=0;i<row2;i++)
for (int j=0;j<col2;j++)
value2[i][j] = sc.nextDouble();
Matrix m2 = new Matrix(value2,row2,col2);
System.out.println("after add:");
System.out.print(m.add(m2).toString());
int row3 = sc.nextInt();
int col3 = sc.nextInt();
double value3[][] = new double[row3][col3];
for(int i=0;i<row3;i++)
for (int j=0;j<col3;j++)
value3[i][j] = sc.nextDouble();
Matrix m3 = new Matrix(value3,row3,col3);
System.out.println("after multiply:");
System.out.print(m.multiply(m3).toString());
System.out.println("after transpose:");
System.out.print(m.transpose().toString());
}
}

139 - 整数数组比较


import java.util.Arrays;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int A[] = new int[num];
int B[] = new int[num];
for(int i=0;i<num;i++){
B[i] = A[i] = sc.nextInt();
}
Arrays.sort(B);
int count1=0,count2=0,count3=0;
for(int i=0;i<num;i++){
if(A[i]>B[i])
count1++;
else if(A[i] == B[i])
count2++;
else
count3++;
}
System.out.println(count1+"n"+count2+"
"+count3);
}
}

142 - 计算机类

import java.util.Scanner;
class CPU{
String model;
double frequency;
int cores;
CPU(String _model,double _frequency,int _cores){
model = _model;
frequency = _frequency;
cores = _cores;
}
CPU(CPU c){
model = c.model;
frequency = c.frequency;
cores = c.cores;
}
@Override
public boolean equals(Object obj) {
CPU c = (CPU)obj;
if(model.equals(c.model)&&frequency==c.frequency&&cores==c.cores)
return true;
else
return false;
}
@Override
public String toString() {
return "CPU:nModel: "+model+"
Frequency: "+String.format("%.1f",frequency)+"
Number of Cores: "+cores;
}
}
class Mainboard{
String model;
Mainboard(String m){
model = m;
}
Mainboard(Mainboard m){
model = m.model;
}
@Override
public boolean equals(Object obj) {
Mainboard m = (Mainboard)obj;
if(model.equals(m.model))
return true;
else
return false;
}
@Override
public String toString() {
return "Mainboard:
Model: "+model;
}
}
class Memory{
String model;
int size;
Memory(String m,int s){
model = m;
size = s;
}
Memory(Memory m){
model = m.model;
size = m.size;
}
@Override
public boolean equals(Object obj) {
Memory m = (Memory)obj;
if(model.equals(m.model)&&size == m.size)
return true;
else
return
false;
}
@Override
public String toString() {
return "Memory:
Model: "+model+"
Size: "+size;
}
}
class Screen{
String model;
int size;
Screen(String m,int s){
model = m;
size = s;
}
Screen(Screen s){
model = s.model;
size = s.size;
}
@Override
public boolean equals(Object obj) {
Screen m = (Screen)obj;
if(model.equals(m.model)&&size == m.size)
return true;
else
return
false;
}
@Override
public String toString() {
return "Screen:
Model: "+model+"
Size: "+size;
}
}
class Harddisk{
String model;
int size;
Harddisk(String m,int s){
model = m;
size = s;
}
Harddisk(Harddisk s){
model = s.model;
size = s.size;
}
@Override
public boolean equals(Object obj) {
Harddisk m = (Harddisk) obj;
if(model.equals(m.model)&&size == m.size)
return true;
else
return
false;
}
@Override
public String toString() {
return "Harddisk:
Model: "+model+"
Size: "+size;
}
}
class Computer{
CPU c;
Mainboard mainboard;
Memory memory;
Screen s;
Harddisk h;
Computer(CPU c,Mainboard mainboard,Memory memory,Screen s,Harddisk h){
this.c = c;
this.mainboard = mainboard;
this.memory = memory;
this.s = s;
this.h = h;
}
@Override
public boolean equals(Object obj) {
Computer computer = (Computer)obj;
if(c.equals(computer.c)&&mainboard.equals(computer.mainboard)&&memory.equals(computer.memory)&&s.equals(computer.s)&&h.equals(computer.h))
return true;
else
return false;
}
@Override
public String toString() {
return c.toString()+"
"+mainboard.toString()+"
"+memory.toString()+"
"+s.toString()+"
"+h.toString();
}
}
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
CPU c1,c2;
Mainboard mainboard1,mainboard2;
Memory memory1,memory2;
Screen s1,s2;
Harddisk h1,h2;
Computer computer1,computer2;
c1 = new CPU(sc.next(),sc.nextDouble(),sc.nextInt());
mainboard1 = new Mainboard(sc.next());
memory1 = new Memory(sc.next(),sc.nextInt());
s1 = new Screen(sc.next(),sc.nextInt());
h1 = new Harddisk(sc.next(),sc.nextInt());
c2 = new CPU(sc.next(),sc.nextDouble(),sc.nextInt());
mainboard2 = new Mainboard(sc.next());
memory2 = new Memory(sc.next(),sc.nextInt());
s2 = new Screen(sc.next(),sc.nextInt());
h2 = new Harddisk(sc.next(),sc.nextInt());
computer1 = new Computer(c1,mainboard1,memory1,s1,h1);
computer2 = new Computer(c2,mainboard2,memory2,s2,h2);
System.out.println(computer1.equals(computer2));
System.out.println("Computer1:
"+computer1.toString());
System.out.println("Computer2:
"+computer2.toString());
}
}

149 - 教师类-2

import java.util.Arrays;
import java.util.Scanner;
class Teacher implements Comparable<Teacher>{
int no;
String name;
int age;
String seminary;
Teacher(int _no,String _name,int _age,String _seminary){
no = _no;
name = _name;
age = _age;
seminary = _seminary;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSeminary() {
return seminary;
}
public void setSeminary(String seminary) {
this.seminary = seminary;
}
public
boolean equals(Object o){
Teacher t = (Teacher)o;
if(no == t.no)
return
true;
else
return
false;
}
public String toString(){
return "no: "+no+", name: "+name+", age: "+age+", seminary: "+seminary;
}
@Override
public int compareTo(Teacher o) {
return no-o.getNo();
}
}
class TeacherManagement{
Teacher t[];
void add(Teacher tt[]){
t = new Teacher[tt.length];
for(int i=0;i<tt.length;i++){
t[i] = new Teacher(tt[i].getNo(),tt[i].getName(),tt[i].getAge(),tt[i].getSeminary());
}
}
public void search(String name){
int i=0;
int flag = 0;
for(;i<t.length;i++){
if(name.equals(t[i].getName())){
System.out.println(t[i].toString());
flag = 1;
}
}
if(flag == 0)
System.out.println("no such teacher");
}
public void search(int age){
int i=0;
int flag = 0;
for(;i<t.length;i++){
if(age == t[i].getAge()){
System.out.println(t[i].toString());
flag = 1;
}
}
if(flag == 0)
System.out.println("no such teacher");
}
}
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
Teacher t[] = new Teacher[num];
for(int i=0;i<num;i++){
t[i] = new Teacher(sc.nextInt(),sc.next(),sc.nextInt(),sc.next());
}
Arrays.sort(t);
for(int i=0;i<num;i++){
System.out.println(t[i].toString());
}
TeacherManagement tm =new TeacherManagement();
tm.add(t);
System.out.println("search by name:");
tm.search(sc.next());
System.out.println("search by age:");
tm.search(sc.nextInt());
}
}

150 - 教师类

import java.util.Scanner;
class Teacher{
int no;
String name;
int age;
String seminary;
Teacher(int _no,String _name,int _age,String _seminary){
no = _no;
name = _name;
age = _age;
seminary = _seminary;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSeminary() {
return seminary;
}
public void setSeminary(String seminary) {
this.seminary = seminary;
}
public
boolean equals(Object o){
Teacher t = (Teacher)o;
if(no == t.no)
return
true;
else
return
false;
}
public String toString(){
return "no: "+no+", name:"+name+", age: "+age+", seminary: "+seminary;
}
}
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Teacher t1,t2;
t1 = new Teacher(sc.nextInt(),sc.next(),sc.nextInt(),sc.next());
t2 = new Teacher(sc.nextInt(),sc.next(),sc.nextInt(),sc.next());
System.out.println(t1.toString());
System.out.println(t2.toString());
System.out.println(t1.equals(t2));
}
}

16 - 十进制转二进制

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
String string = "";
while(N>0) {
if(N%2==0)
string += "0";
else
string += "1";
N/=2;
}
String tmp = new StringBuilder(string).reverse().toString();
System.out.println(tmp);
}
}

 

最后

以上就是开心人生为你收集整理的java作业合集168 - 学生Map167 - 学生列表166 - 比较日期158 - 打印双休日165 - 数据类型判断164 - 解析二维数组163 - 各类字符数162 - 字符串153 - 判断回文140 - 家电类151 - 矩阵类139 - 整数数组比较142 - 计算机类149 - 教师类-2150 - 教师类16 - 十进制转二进制的全部内容,希望文章能够帮你解决java作业合集168 - 学生Map167 - 学生列表166 - 比较日期158 - 打印双休日165 - 数据类型判断164 - 解析二维数组163 - 各类字符数162 - 字符串153 - 判断回文140 - 家电类151 - 矩阵类139 - 整数数组比较142 - 计算机类149 - 教师类-2150 - 教师类16 - 十进制转二进制所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部