tag:blogger.com,1999:blog-694855878384792308.post5747333379322963607..comments2024-03-21T06:26:49.387-07:00Comments on Java67: How to Find Greatest Common Divisor of two numbers in Java - [ Euclid's algorithm GCD Example]javin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger26125tag:blogger.com,1999:blog-694855878384792308.post-89180270069922964692022-11-03T05:31:40.268-07:002022-11-03T05:31:40.268-07:00how can i reduce 6/3 with pgdc ?how can i reduce 6/3 with pgdc ?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-44105205162435447082022-10-12T20:06:02.803-07:002022-10-12T20:06:02.803-07:00Can anyone say java or python is best to crack pro...Can anyone say java or python is best to crack product based companyAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-45760166317104759522022-06-30T17:59:59.556-07:002022-06-30T17:59:59.556-07:00public static void greatestCommonDivisor(float num... public static void greatestCommonDivisor(float num,float num2){<br /> float i = Math.max(num, num2);<br /> while ((num2 / i) % 1 != 0 || (num / i) % 1 != 0){<br /> i --;<br /> }<br /> System.out.printf("your Greatest Common Divisor(GCD) is: %.0f",i);<br /> }javaLoverhttps://www.blogger.com/profile/14680680008975144361noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-19731697443734794072021-11-19T03:32:41.490-08:002021-11-19T03:32:41.490-08:00I'm looking to find the gcd for 3 values and n...I'm looking to find the gcd for 3 values and not two. Any comments? <br />Anonymoushttps://www.blogger.com/profile/09973510718285542375noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-6398481534476950022020-05-12T21:50:10.204-07:002020-05-12T21:50:10.204-07:00plz help me 2 find gcd of 2 user entered numbers u...plz help me 2 find gcd of 2 user entered numbers using repeated division methid.<br />Anonymoushttps://www.blogger.com/profile/13644295742276851676noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-40626401032360265462020-04-30T05:24:49.777-07:002020-04-30T05:24:49.777-07:00is this a homework?is this a homework?javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-32641086176168708052020-04-27T21:13:51.426-07:002020-04-27T21:13:51.426-07:00create a class rational which represents rational ...create a class rational which represents rational number by two double values numerator and denominator. include default and parametrized constructor. create a method to check if rational number is terminating or not. if we got remainder as zero then the rational number is called termination rational number otherwise non-terminating. also create a method to compare two rational number which accept one argument of rational type and will return true/false if the passed argument is larger/smaller.WAP in java??Kulveerhttps://www.blogger.com/profile/04526737753486585405noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-74799627901684539032020-03-20T07:26:37.828-07:002020-03-20T07:26:37.828-07:00Thank you, glad that you find it usefulThank you, glad that you find it usefuljavin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-8876425968587596992020-03-18T09:55:13.522-07:002020-03-18T09:55:13.522-07:00this was a lovely readthis was a lovely readAnonymoushttps://www.blogger.com/profile/14055415474552025772noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-78797780022964467052020-02-23T20:45:34.055-08:002020-02-23T20:45:34.055-08:00Program for String anagram
=======================...Program for String anagram<br />==========================<br /><br />import java .util.*;<br />class str_ana<br />{<br /> static void main()<br /> {<br /> Scanner sc= new Scanner (System.in);<br /> System.out.println("Enter 2 Strings to be checked");<br /> String wd1 = sc.nextLine();<br /> String wd2 = sc.nextLine();<br /> wd1 = wd1.trim(); //removing extra spaces<br /> wd2 = wd2.trim(); //removing extra spaces<br /> int l1=wd1.length();<br /> int l2= wd2.length();<br /> if(l1!=l2) //checking whether the length is equal<br /> {<br /> System.out.println("not anagram");<br /> }<br /> else<br /> {<br /> char a[] = new char[l1];//initiallising array to check anagram<br /> char b[] = new char[l1];//l1 can be used as both their lengths are same<br /> int i,j,f=0;<br /> for( i=0; i<l1;i++)<br /> {<br /> a[i] = wd1.charAt(i);//initiallising characters of words for both arrays <br /> b[i] = wd2.charAt(i);<br /> }<br /> for(i=0;i<l1;i++) //this loop is used to give null value for the characters that are equal <br /> {<br /> for(j=0;j<l1;j++)<br /> {<br /> char ch = b[i];<br /> if (ch ==(a[j]))// checking for equality<br /> {<br /> b[i]= ' ';<br /> continue;<br /> }<br /> }<br /> }<br /> for(i=0; i<l1;i++)//loop for checking whether all characters are replaced by null value(here space)<br /> {<br /> if (b[i] != ' ')<br /> {<br /> f =1;<br /> }<br /> }<br /> if(f==1)<br /> System.out.println("Not an anagram");<br /> else<br /> System.out.println("Anagram");<br /> }<br /> }<br /> } <br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-82383131162143514602019-11-06T03:45:29.269-08:002019-11-06T03:45:29.269-08:00static int greatestDivisor(int x, int y){
... static int greatestDivisor(int x, int y){<br /> //create list to show what x and y can be divided with<br /> ArrayList divisorsList = new ArrayList<>();<br /> int divisor = 1;<br /><br /> //loop till both cannot be divided further<br /> while(x/divisor > 0 || y/divisor > 0){<br /> if(x%divisor == 0 && y%divisor==0){<br /> divisorsList.add(divisor);<br /> }<br /> divisor++;<br /> }<br /><br /> //printing out list of all common divisors<br />// for(int div: divisorsList){<br />// System.out.println(div);<br />// }<br /><br /> //last added divisor is the greatest common divisor<br /> return divisorsList.get(divisorsList.size()-1);<br /><br /> }Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-60562434360176812242019-09-25T22:32:15.006-07:002019-09-25T22:32:15.006-07:00It uses recursion which will cause stackoverflow i...It uses recursion which will cause stackoverflow if the numbers are very large, so an iterative approach is betterMuaz Razaqhttps://www.blogger.com/profile/17563468254082512263noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-10656851034577821052019-06-19T09:54:28.718-07:002019-06-19T09:54:28.718-07:00String Anagram
==================
Write a program ...String Anagram<br />==================<br />Write a program to check if two given String is Anagram of each other. Your function should return true if two Strings are Anagram, false otherwise. A string is said to be an anagram if it contains same characters and same length but in different order e.g. army and Mary are anagrams. You can ignore cases for this problem but you should clarify that from your interview.<br />siva medabalmihttps://www.blogger.com/profile/03966250311929933124noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-2755692635432318692018-08-09T08:32:31.877-07:002018-08-09T08:32:31.877-07:00This code is super cool!!
Can anyone do this with...This code is super cool!!<br /><br />Can anyone do this with array of integers that the user can give inputs at the console?Anonymoushttps://www.blogger.com/profile/02954148142073762269noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-20587237325923372022017-10-12T04:56:50.821-07:002017-10-12T04:56:50.821-07:00logic above takes n1 > n2, so n1 & n2 shoul...logic above takes n1 > n2, so n1 & n2 should be swapped if n1 < n2Anonymoushttps://www.blogger.com/profile/11314284928850354990noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-62587821528051066382017-09-14T12:41:55.939-07:002017-09-14T12:41:55.939-07:00The flowchart is wrong. After x=y then x%y = 0 al...The flowchart is wrong. After x=y then x%y = 0 always. Your program is simultaneously resetting x and y with the same original x and y for each reset.Charlie-Boohttps://www.blogger.com/profile/03253832629640675379noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-76139955763416049692017-07-14T04:52:48.796-07:002017-07-14T04:52:48.796-07:00LCD=(n1*n2)/GCDLCD=(n1*n2)/GCDAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-1377769987233123472016-10-19T23:19:44.438-07:002016-10-19T23:19:44.438-07:00Can you show the code without a recursion methodCan you show the code without a recursion methodmendoza3300https://www.blogger.com/profile/02651703465592944166noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-19407886181811775222015-12-13T02:40:46.049-08:002015-12-13T02:40:46.049-08:00nice...thnx...i think it gave me only one error wh...nice...thnx...i think it gave me only one error where i had to import scanner separately...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-56502141330457819532014-12-09T00:40:48.178-08:002014-12-09T00:40:48.178-08:00Please help with recursive method for lcm Please help with recursive method for lcm Anonymoushttps://www.blogger.com/profile/13428663721497033259noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-5360851292178310372014-11-02T05:51:33.434-08:002014-11-02T05:51:33.434-08:00plz help me with this....Wap in Java to input two ...plz help me with this....Wap in Java to input two numbers in LCM and GCM make use of the function<br />1.void take(int a,int b)-to take the value of a and b.<br />2.void calculate-calculate GCD and LCM.<br />3.void show-display output. Anonymoushttps://www.blogger.com/profile/08578198535395703442noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-18102863187150429752014-07-14T04:18:39.377-07:002014-07-14T04:18:39.377-07:00plz tell me gcd program via factorialplz tell me gcd program via factorialAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-59055469338856609742014-03-18T04:36:44.831-07:002014-03-18T04:36:44.831-07:00i built a program w/c is suppose to calculate GCD ...i built a program w/c is suppose to calculate GCD and LCD but i dont know where to insert its formula?? <br />here is my code..<br /><br />import java.awt.*;<br />import java.awt.event.*;<br />import javax.swing.*;<br /><br />public class Distruc extends JFrame implements ActionListener{<br /><br /> Container con;<br /> JLabel lbl1,lbl2,lbl3;<br /> JTextField txt1,txt2,txt3;<br /> JButton btn1,btn2,btn3;<br /><br /> public Distruc(){<br /> con = getContentPane();<br /> con.setLayout(new FlowLayout());<br /><br /> txt1 = new JTextField(10);<br /> txt2 = new JTextField(10);<br /> txt3 = new JTextField(10);<br /><br /> lbl1 = new JLabel("INPUT 1: ");<br /> lbl2 = new JLabel("INPUT 2: ");<br /> lbl3 = new JLabel("RESULT: ");<br /><br /> btn1 = new JButton("GCD");<br /> btn1.addActionListener(this);<br /> btn2 = new JButton("LCD");<br /> btn2.addActionListener(this);<br /> btn3 = new JButton("DONE");<br /> btn3.addActionListener(this);<br /><br /> txt1.setText("");<br /> txt2.setText("");<br /> txt3.setText("");<br /><br /> con.add(lbl1);<br /> con.add(txt1);<br /> con.add(lbl2);<br /> con.add(txt2);<br /> con.add(btn1);<br /> con.add(btn2);<br /> con.add(lbl3);<br /> con.add(txt3);<br /> con.add(btn3);<br /><br /> }<br /><br /> public void actionPerformed(ActionEvent e){<br /> try{<br /> Object sc = e.getSource();<br /><br /> String a = txt1.getText();<br /> String b = txt2.getText();<br /><br /> if(sc==btn1){<br /> <br /><br /><br /> }<br /> else if(sc==btn2){<br /><br /> }<br /> else if(sc==btn3){<br /> System.exit(0);<br /> }<br /> }<br /> catch(NumberFormatException error){<br /> JOptionPane.showMessageDialog(null, "Error");<br /><br /> }<br /> }<br /> public static void main(String[]args){<br /><br /> Distruc dt = new Distruc();<br /><br /> dt.setSize(170,240);<br /> dt.setVisible(true);<br /> dt.setResizable(false);<br /> dt.setTitle("Distruc");<br /> dt.setLocationRelativeTo(null);<br /> dt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br /> }<br />}<br /><br />pls help...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-54539298488556430052013-10-04T01:44:50.543-07:002013-10-04T01:44:50.543-07:00private static int findlcm(int number1, int number...private static int findlcm(int number1, int number2) {<br /> int lcm=0;<br /> for(int i=1;i<=number2;i++){<br /> lcm=number1*i;<br /> if(lcm%number2==0){<br /> break;<br /> }<br /> }<br /> return lcm;<br /> }Anonymoushttps://www.blogger.com/profile/11166332451489357599noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-70127634531554099432013-08-29T20:11:18.817-07:002013-08-29T20:11:18.817-07:00What is the other way of calculating GCD in Java p...What is the other way of calculating GCD in Java program, apart from Euclid's method, a comparison would be nice.Joenoreply@blogger.com