Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0d3292c

Browse files
Irani-LaptopIrani-Laptop
Irani-Laptop
authored and
Irani-Laptop
committed
first time
1 parent f352da2 commit 0d3292c

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
eclipse.preferences.version=1
2+
encoding//src/P84.java=UTF-8
23
encoding//src/P85.java=UTF-8
34
encoding//src/P86.java=UTF-8
45
encoding//src/P87.java=UTF-8

‎P85P86/src/P84.java

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* P86 : ضرب و جمع در مبنای 8
3+
*
4+
* @author Gholamali Nejad Hajali Irani
5+
* @version 1.0
6+
* @since 2021年02月05日
7+
* @Team gClassAcademy
8+
* @Website youtube.com/gClassAcademy
9+
*
10+
*/
11+
12+
import java.util.Scanner;
13+
14+
public class P84
15+
{
16+
public static void main(String[] args)
17+
{
18+
Scanner input=new Scanner (System.in);
19+
20+
System.out.print("Enter n1,n2 (8): ");
21+
long n1 = input.nextLong(); // برای عدد گرفته شده از کاربر
22+
long n2 = input.nextLong(); // برای عدد گرفته شده از کاربر
23+
24+
25+
26+
///////////// تبدیل اعداد از 8 به مبنای 10
27+
28+
long s1=0; // معادل n1 در مبنای 10
29+
long p=1; //برای تولید توانهای 2
30+
while (n1>0)
31+
{
32+
s1 = s1 + p * (n1 % 10);
33+
p = p*8;
34+
n1 = n1 / 10;
35+
}
36+
//System.out.println(s1);
37+
38+
long s2=0; // معادل n2 در مبنای 10
39+
p=1; //برای تولید توانهای 2
40+
while (n2>0)
41+
{
42+
s2 = s2 + p * (n2 % 10);
43+
p = p*8;
44+
n2 = n2 / 10;
45+
}
46+
//System.out.println(s2);
47+
48+
49+
////////////////// عملیات در مبنای 10
50+
51+
long sum=s1+s2; // برای جمع دو عدد
52+
long product = s1*s2; // برای ضرب دو عدد
53+
54+
55+
////////////////////// تبدیل از 10 به 8
56+
57+
long s=0; // برای حاصل جمع نهایی
58+
p=1; //برای تولید توانهای 10
59+
while (sum>0)
60+
{
61+
s = s + p * (sum%8);
62+
p = p*10;
63+
sum = sum/8;
64+
}
65+
System.out.println("\nSum in base 8 is: " + s);
66+
67+
68+
69+
70+
long ss=0; // برای حاصل جمع نهایی
71+
p=1; //برای تولید توانهای 10
72+
while (product>0)
73+
{
74+
ss = ss + p * (product%8);
75+
p = p*10;
76+
product = product/8;
77+
}
78+
System.out.println("Product in base 8 is: " + ss);
79+
80+
81+
82+
83+
}// end of main
84+
}// end of class
85+
86+
87+
88+
89+
90+
91+
92+
93+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /